﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;
using Sharp.DataTransferObject;
using Sharp.DataTransferObject.Workflow;
using Sharp.Domain.PlatformBoundedContext.ConfigModule;
using Sharp.Domain.PlatformBoundedContext.MasterDataModule.Aggregates;
using Sharp.Domain.PlatformBoundedContext.MessageModule.Aggregates;
using Sharp.Domain.PlatformBoundedContext.OrgModule.Aggregates;
using Sharp.Domain.PlatformBoundedContext.PermissionModule.Aggregates;
using Sharp.Domain.PlatformBoundedContext.PersonModule.Aggregates;
using Sharp.Domain.PlatformBoundedContext.PlatformModule.Aggregates;
using Sharp.Domain.PlatformBoundedContext.UserModule.Aggregates;
using Sharp.Domain.PlatformBoundedContext.WorkFlowModule.Aggregates;
using Sharp.Domain.PlatformBoundedContext.WorkFlowModule.Engine.Business.EntitySQLServer;
using Sharp.Domain.PlatformBoundedContext.WorkFlowModule.Engine.Xpdl;
using Sharp.Domain.PlatformBoundedContext.WorkFlowModule.Engine.Xpdl.Node;

namespace Sharp.Application.Platform
{
    public class AutoMapperProfile : Profile
    {
        public AutoMapperProfile()
        {
            #region 用户
            this.CreateMap<UserDTO, User>()
                    .ReverseMap();
            this.CreateMap<UserProfileDTO, UserProfile>()
                .ReverseMap();
            this.CreateMap<RoleDTO, Role>()
                .ReverseMap();
            this.CreateMap<PermissionDTO, Permission>()
                .ReverseMap();
            this.CreateMap<PermissionDTO, AvailablePermission>()
                .ReverseMap();
            this.CreateMap<Message, MessageDTO>()
                .ReverseMap();
            this.CreateMap<User, MessageDTO.UserDTO>()
                                   .ReverseMap();

            this.CreateMap<Notice, NoticeDTO>()
                .ReverseMap();
            #endregion

            #region 员工模块
            this.CreateMap<PersonDTO, Person>().ReverseMap();
            this.CreateMap<EmployeeDTO, Person>().ReverseMap();
            this.CreateMap<EmployeeDTO, Employee>().ReverseMap();
            this.CreateMap<GroupDTO, Group>().ReverseMap();
            this.CreateMap<JobDTO, Job>().ReverseMap();
            #endregion

            #region 组织
            this.CreateMap<OrgDTO, Org>().ReverseMap();
            this.CreateMap<OrgLevelDTO, OrgLevel>().ReverseMap();
            #endregion

            #region 主数据
            //var application = Assembly.LoadFrom(WebServer.MapPath(@"~\bin\Sharp.Domain.PlatformBoundedContext.dll"));
            //foreach (var type in application.GetTypes())
            //{
            //    if (type.GetInterface("IMasterData", false) == typeof(IMasterData))
            //    {
            //        this.CreateMap(type, typeof(MasterDataDTO));
            //        this.CreateMap(typeof(MasterDataDTO), type);
            //    }
            //}
            this.CreateMap<MasterDataSimpleDTO, MasterData>().ReverseMap();
            this.CreateMap<MasterDataDTO, MasterData>().ReverseMap();
            this.CreateMap<MasterDataCategoryDTO, MasterDataCategory>().ReverseMap();
            #endregion

            #region 平台相关
            this.CreateMap<SubSystemDTO, SubSystem>().ReverseMap();
            this.CreateMap<UserLogDTO, UserLog>().ReverseMap();
            #endregion

            #region 配置

            this.CreateMap<OAuthConfig, OAuthConfigDTO>()
               .ReverseMap();

            #endregion



            #region 工作流
            this.CreateMap<ActivityDTO, ActivityEntity>()
                                   .ReverseMap();
            this.CreateMap<ActivityInstanceDTO, ActivityInstanceEntity>()
                                   .ReverseMap();
            this.CreateMap<LogDTO, LogDTO>()
                                   .ReverseMap();
            this.CreateMap<NodeBaseDTO, NodeBase>()
                .ReverseMap();
            this.CreateMap<ProcessDTO, ProcessEntity>()
                     .ReverseMap();
            this.CreateMap<ProcessFileDTO, ProcessFileEntity>()
                                  .ReverseMap();
            this.CreateMap<ProcessInstanceDTO, ProcessInstanceEntity>()
                                  .ReverseMap();
            this.CreateMap<TaskDTO, TaskEntity>()
                                  .ReverseMap();
            this.CreateMap<TransitionInstanceDTO, TransitionInstanceEntity>()
                                  .ReverseMap();



            #endregion

            

        }
    }
}
